package com.lkd.handler;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.lkd.business.MsgHandler;
import com.lkd.config.TopicConfig;
import com.lkd.contract.SupplyChannel;
import com.lkd.contract.SupplyContract;
import com.lkd.emq.Topic;
import com.lkd.exception.LogicException;
import com.lkd.service.VendingMachineService;
import com.lkd.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;


@Component
@Topic(TopicConfig.VMS_SUPPLY_TOPIC)
public class TaskSupplyCompletedHandler implements MsgHandler {
    @Autowired
    private VendingMachineService vendingMachineService;

    @Override
    public void process(String jsonMsg) throws IOException {
        // 反序列化
        SupplyContract contract = JsonUtil.getByJson(jsonMsg, SupplyContract.class);

        // 检查参数
        if (contract == null) {
            throw new LogicException("完成工单协议为空");
        }

        // 修改货道信息和最新补货时间
        vendingMachineService.supply(contract);

    }
}
